﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CRM.DataAccess.Entities;
using CRM.Business.Services;
using CRM.Encryption;
using Telerik.Web.UI;
using System.IO;

namespace Web.Description_Details
{
    public partial class AddNewDescriptionDetail : System.Web.UI.Page
    {
        static string prevPage = String.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;
            if (Request.UrlReferrer != null)
                prevPage = Request.UrlReferrer.ToString();
        }

        private int addNewDescription()
        {
            DESCRIPTION_DETAILS dd = new DESCRIPTION_DETAILS();
            DateTime dt = DateTime.Now;
            dd.DATE_CREATED = dt;
            dd.DESCRIPTION = txtDescription.Text.Trim();
            dd.DESCRIPTION_NAME = txtDescriptionName.Text.Trim();
            
            return DescriptionDetailService.AddNewDescription(dd);
        }
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            int checkDes = DescriptionDetailService.CheckExist(txtDescriptionName.Text.Trim());
            if (checkDes == 0)
            {
                int add = addNewDescription();
                if (add == 1)
                {
                    RadAjaxManager.GetCurrent(this).ResponseScripts.Add(@"ShowMessageAndRedirect('" + "Add new Description Detail successful !" + "','" + "DescriptionDetails.aspx" + "');");
                    //MessageBox.Show(this.Page, Page.GetType(), "Add new Role successful !", "Roles.aspx");
                }
                else
                    RadAjaxManager.GetCurrent(this).ResponseScripts.Add(@"ShowMessage('" + "Can not add new Description Detail !" + "');");
                //MessageBox.Show(this.Page, Page.GetType(), "Cannot add new Role !", "");

            }
            else if (checkDes == 1)
                RadAjaxManager.GetCurrent(this).ResponseScripts.Add(@"ShowMessage('" + "Description Name already exists !" + "');");
            //MessageBox.Show(this.Page, Page.GetType(), "Role Name already exists !", "");
        }
        protected void btn_Cancel_Click(object sender, EventArgs e)
        {
            Response.Redirect(prevPage);
        }
        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
        {

        }
    }
}